import { Controller, Inject, Get, Query, Body, Post, Put, Param, Del } from '@midwayjs/core';
import { MenuService } from "@service/system/menu.service";
import { ListMenuDTO, CreateMenuDTO, UpdateMenuDTO } from "@dto/system/menu.dto";
import { Auth } from "@decorator/auth.decorator";
import { BusinessType, Log } from "@decorator/log.decorator";

@Controller('/system/menu')
export class PostController {
  @Inject()
  menuService: MenuService;

  // 获取列表
  @Auth('system:menu:list')
  @Get('/list')
  async list(@Query() queryParams: ListMenuDTO) {
    return await this.menuService.list(queryParams);
  }

  // 新增
  @Auth('system:menu:add')
  @Log({ title: '菜单管理', businessType: BusinessType.ADD })
  @Post('/')
  async create(@Body() menu: CreateMenuDTO) {
    return await this.menuService.create(menu);
  }

  // 删除
  @Auth('system:menu:remove')
  @Log({ title: '菜单管理', businessType: BusinessType.REMOVE })
  @Del('/:menuId')
  async delete(@Param('menuId') menuId: string) {
    return await this.menuService.delete(menuId);
  }

  // 修改
  @Auth('system:menu:edit')
  @Log({ title: '菜单管理', businessType: BusinessType.EDIT })
  @Put('/')
  async update(@Body() menu: UpdateMenuDTO) {
    return await this.menuService.update(menu);
  }

  // 获取详情
  @Auth('system:menu:query')
  @Get('/:menuId')
  async get(@Param('menuId') menuId: number) {
    return await this.menuService.detail(menuId);
  }

  // 树状结构
  @Get('/treeselect')
  async treeSelect() {
    return await this.menuService.treeSelect();
  }

  // 根据角色ID查询菜单下拉树结构
  @Get('/roleMenuTreeselect/:roleId')
  async roleMenuTreeSelect(@Param('roleId') roleId: number) {
    return this.menuService.getTreeSelectByRoleId(roleId);
  }
}
